package io.renren.modules.business.controller;

import com.baidu.ueditor.ActionEnter;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

/**
 * 用于处理关于ueditor插件相关的请求
 *
 * @author liao mengqing
 */
@RestController
@CrossOrigin
@RequestMapping("/business/ueditor")
public class UeditorController {
    /**
     * 通过action=""不同的类型来处理请求
     * action=config为加载配置项，actio=uploadimg为图片上传
     * 当action=config时，保证前端的编辑器各项文件上传功能能正常使用
     * @param request
     * @return
     * @throws UnsupportedEncodingException
     */
    @RequestMapping(value = "/exec")
    @ResponseBody
    public String exec(HttpServletRequest request) throws UnsupportedEncodingException {
        request.setCharacterEncoding("utf-8");
        String rootPath = request.getRealPath("/");
        return new ActionEnter(request, rootPath).exec();
    }
}
